{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5cb2cbba",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "002d558f",
   "metadata": {},
   "source": [
    "*r是指response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4016e33c",
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.get(\"https://cn.bing.com\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71a8bb63",
   "metadata": {},
   "source": [
    "*r.content\n",
    ">1.可以获取请求数据内容（观察页面数据形态 HTML,Json）\n",
    ">2.b是指bytes:二进制文件\n",
    "*r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "89227141",
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.get('http://httpbin.org/get')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7717819f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'args': {},\n",
       " 'headers': {'Accept': '*/*',\n",
       "  'Accept-Encoding': 'gzip, deflate',\n",
       "  'Host': 'httpbin.org',\n",
       "  'User-Agent': 'python-requests/2.25.1',\n",
       "  'X-Amzn-Trace-Id': 'Root=1-623ec8af-14bf5d72433d0a7a48f174b0'},\n",
       " 'origin': '120.85.42.44',\n",
       " 'url': 'http://httpbin.org/get'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1b9f8b95",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\\n  \"args\": {}, \\n  \"headers\": {\\n    \"Accept\": \"*/*\", \\n    \"Accept-Encoding\": \"gzip, deflate\", \\n    \"Host\": \"httpbin.org\", \\n    \"User-Agent\": \"python-requests/2.25.1\", \\n    \"X-Amzn-Trace-Id\": \"Root=1-623ec8b5-233470371b68d7c31fa0b623\"\\n  }, \\n  \"origin\": \"120.85.42.44\", \\n  \"url\": \"https://httpbin.org/get\"\\n}\\n'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54b6da0d",
   "metadata": {},
   "source": [
    " *3. playload 使用playload请求"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "db8f64b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "payload = {\n",
    "   'name':'qianya',\n",
    "    'JOB':'IT'\n",
    "}\n",
    "r = requests.get('https://httpbin.org/get')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ea1f2bc3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e65e3ae",
   "metadata": {},
   "source": [
    "# 2.face++ detect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ab6b208c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.准备base url (对应该功能的url链接)\n",
    "face_detect_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "\n",
    "# 2. 准备参数数据\n",
    "payload = {\n",
    "    'api_key':'ZHfPcJzmzX_EdU6JQAnXU2s9rLQxXcD8',\n",
    "    'api_secret':'EM8ZGZ8gmpSD4aqAGTZ2EQgNCP8-v2AR',\n",
    "    'image_url':'https://img0.baidu.com/it/u=1456453464,2315522827&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=334',\n",
    "    'return_landmark':1,\n",
    "    'return_attributes':'gender,age,smiling,headpose'\n",
    "}\n",
    "# 3. 检查调用的请求方法：post\n",
    "# 4. 请求人脸数据\n",
    "r = requests.post(url = face_detect_url,params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7cd468a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "74d1be2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648281921,0603f911-97b7-4964-bca8-af5c3c15e9f9',\n",
       " 'time_used': 204,\n",
       " 'faces': [{'face_token': 'e676ff821e6b6ead902ef4c2865b64d7',\n",
       "   'face_rectangle': {'top': 79, 'left': 257, 'width': 153, 'height': 153},\n",
       "   'landmark': {'contour_chin': {'x': 304, 'y': 236},\n",
       "    'contour_left1': {'x': 257, 'y': 122},\n",
       "    'contour_left2': {'x': 257, 'y': 136},\n",
       "    'contour_left3': {'x': 257, 'y': 149},\n",
       "    'contour_left4': {'x': 260, 'y': 163},\n",
       "    'contour_left5': {'x': 266, 'y': 176},\n",
       "    'contour_left6': {'x': 273, 'y': 189},\n",
       "    'contour_left7': {'x': 279, 'y': 202},\n",
       "    'contour_left8': {'x': 285, 'y': 215},\n",
       "    'contour_left9': {'x': 292, 'y': 229},\n",
       "    'contour_right1': {'x': 401, 'y': 107},\n",
       "    'contour_right2': {'x': 404, 'y': 126},\n",
       "    'contour_right3': {'x': 404, 'y': 146},\n",
       "    'contour_right4': {'x': 402, 'y': 166},\n",
       "    'contour_right5': {'x': 395, 'y': 185},\n",
       "    'contour_right6': {'x': 383, 'y': 202},\n",
       "    'contour_right7': {'x': 366, 'y': 215},\n",
       "    'contour_right8': {'x': 347, 'y': 226},\n",
       "    'contour_right9': {'x': 326, 'y': 234},\n",
       "    'left_eye_bottom': {'x': 271, 'y': 123},\n",
       "    'left_eye_center': {'x': 270, 'y': 120},\n",
       "    'left_eye_left_corner': {'x': 261, 'y': 121},\n",
       "    'left_eye_lower_left_quarter': {'x': 266, 'y': 123},\n",
       "    'left_eye_lower_right_quarter': {'x': 276, 'y': 121},\n",
       "    'left_eye_pupil': {'x': 272, 'y': 119},\n",
       "    'left_eye_right_corner': {'x': 280, 'y': 119},\n",
       "    'left_eye_top': {'x': 270, 'y': 117},\n",
       "    'left_eye_upper_left_quarter': {'x': 265, 'y': 119},\n",
       "    'left_eye_upper_right_quarter': {'x': 275, 'y': 117},\n",
       "    'left_eyebrow_left_corner': {'x': 258, 'y': 101},\n",
       "    'left_eyebrow_lower_left_quarter': {'x': 263, 'y': 101},\n",
       "    'left_eyebrow_lower_middle': {'x': 268, 'y': 100},\n",
       "    'left_eyebrow_lower_right_quarter': {'x': 273, 'y': 100},\n",
       "    'left_eyebrow_right_corner': {'x': 279, 'y': 99},\n",
       "    'left_eyebrow_upper_left_quarter': {'x': 262, 'y': 98},\n",
       "    'left_eyebrow_upper_middle': {'x': 267, 'y': 96},\n",
       "    'left_eyebrow_upper_right_quarter': {'x': 274, 'y': 96},\n",
       "    'mouth_left_corner': {'x': 279, 'y': 187},\n",
       "    'mouth_lower_lip_bottom': {'x': 300, 'y': 201},\n",
       "    'mouth_lower_lip_left_contour1': {'x': 288, 'y': 193},\n",
       "    'mouth_lower_lip_left_contour2': {'x': 283, 'y': 195},\n",
       "    'mouth_lower_lip_left_contour3': {'x': 289, 'y': 201},\n",
       "    'mouth_lower_lip_right_contour1': {'x': 319, 'y': 188},\n",
       "    'mouth_lower_lip_right_contour2': {'x': 328, 'y': 188},\n",
       "    'mouth_lower_lip_right_contour3': {'x': 315, 'y': 197},\n",
       "    'mouth_lower_lip_top': {'x': 299, 'y': 193},\n",
       "    'mouth_right_corner': {'x': 338, 'y': 177},\n",
       "    'mouth_upper_lip_bottom': {'x': 297, 'y': 181},\n",
       "    'mouth_upper_lip_left_contour1': {'x': 289, 'y': 175},\n",
       "    'mouth_upper_lip_left_contour2': {'x': 281, 'y': 180},\n",
       "    'mouth_upper_lip_left_contour3': {'x': 287, 'y': 183},\n",
       "    'mouth_upper_lip_right_contour1': {'x': 302, 'y': 173},\n",
       "    'mouth_upper_lip_right_contour2': {'x': 320, 'y': 173},\n",
       "    'mouth_upper_lip_right_contour3': {'x': 316, 'y': 177},\n",
       "    'mouth_upper_lip_top': {'x': 296, 'y': 175},\n",
       "    'nose_contour_left1': {'x': 283, 'y': 118},\n",
       "    'nose_contour_left2': {'x': 276, 'y': 140},\n",
       "    'nose_contour_left3': {'x': 280, 'y': 156},\n",
       "    'nose_contour_lower_middle': {'x': 289, 'y': 159},\n",
       "    'nose_contour_right1': {'x': 304, 'y': 115},\n",
       "    'nose_contour_right2': {'x': 307, 'y': 139},\n",
       "    'nose_contour_right3': {'x': 301, 'y': 156},\n",
       "    'nose_left': {'x': 273, 'y': 151},\n",
       "    'nose_right': {'x': 312, 'y': 150},\n",
       "    'nose_tip': {'x': 282, 'y': 146},\n",
       "    'right_eye_bottom': {'x': 329, 'y': 113},\n",
       "    'right_eye_center': {'x': 329, 'y': 110},\n",
       "    'right_eye_left_corner': {'x': 316, 'y': 114},\n",
       "    'right_eye_lower_left_quarter': {'x': 322, 'y': 114},\n",
       "    'right_eye_lower_right_quarter': {'x': 336, 'y': 111},\n",
       "    'right_eye_pupil': {'x': 329, 'y': 109},\n",
       "    'right_eye_right_corner': {'x': 343, 'y': 108},\n",
       "    'right_eye_top': {'x': 327, 'y': 105},\n",
       "    'right_eye_upper_left_quarter': {'x': 320, 'y': 108},\n",
       "    'right_eye_upper_right_quarter': {'x': 335, 'y': 106},\n",
       "    'right_eyebrow_left_corner': {'x': 301, 'y': 95},\n",
       "    'right_eyebrow_lower_left_quarter': {'x': 313, 'y': 90},\n",
       "    'right_eyebrow_lower_middle': {'x': 325, 'y': 85},\n",
       "    'right_eyebrow_lower_right_quarter': {'x': 338, 'y': 85},\n",
       "    'right_eyebrow_right_corner': {'x': 350, 'y': 88},\n",
       "    'right_eyebrow_upper_left_quarter': {'x': 310, 'y': 85},\n",
       "    'right_eyebrow_upper_middle': {'x': 324, 'y': 79},\n",
       "    'right_eyebrow_upper_right_quarter': {'x': 338, 'y': 80}},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 22},\n",
       "    'smile': {'value': 98.361, 'threshold': 50.0},\n",
       "    'headpose': {'pitch_angle': -6.181054,\n",
       "     'roll_angle': -9.124897,\n",
       "     'yaw_angle': 21.321772}}}],\n",
       " 'image_id': 'cPQOa1a2UeDVcpuSVsfqSQ==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3145ed76",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
